package org.goldfish.distributed_framework.client;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

public class ServiceDiscovery {
    public static String lookup(String serviceName, String registryAddress) throws Exception {
        String requestUrl = registryAddress + "/query?service=" + serviceName;
        URL url = new URL(requestUrl);

        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        conn.setRequestMethod("GET");

        BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
        String result = reader.readLine();
        reader.close();

        System.out.println("[ServiceDiscovery] 查找到服务地址: " + result);
        return result;
    }
}
